#include "CE.h"
#include "CE_App.h"

using namespace pugi;

CE_SINGLETON_INIT(CE_App);

CE_App::CE_App(void)
{
}


CE_App::~CE_App(void)
{
}

bool CE_App::load(const char* filePath)
{
	xml_document xml;
	xml_parse_result result = xml.load_file(filePath);
	if(!result)
		return false;

	xpath_node projectNode = xml.select_single_node(CE_XPATH_PROJECT);
	if(!projectNode)
		return false;
	xml_attribute nameAttr = projectNode.node().attribute(CE_ATTR_NAME);
	if(!nameAttr)
		return false;
	const char* projectName = nameAttr.value();

	xpath_node_set sceneNodes = xml.select_nodes(CE_XPATH_SCENE);
	
	return sceneManager->setScenes(sceneNodes);
}

int CE_App::play()
{
	CE_Scene* startScene = sceneManager->startScene();
	if(startScene)
		startScene->setCurrentScene();
	else
		return CE_ErrorCodes::NoStartScene;
	
	return CE_ErrorCodes::NoError;
}

void CE_App::pause()
{
}

void CE_App::stop()
{
}
